<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<script type="text/javascript" src="../js/jquery-1.8.0.min.js" ></script>
		<script type="text/javascript" src="../js/head_public.js" ></script>
	    <script type="text/javascript" src="../js/uploadPreview.js" ></script>
		<style>
			.file{position: absolute;top: 0rem;right:0.1rem ;z-index: 1;opacity: 0;}
			.kong{background: #efeff4;}
			#zhuangtai{text-align: center;}
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav ding-bar">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">绑定电梯卡</h1>
		</header>
		<div class="mui-content" >
			
		    <form class="changep-form" style="background: #fff;">
		    	<!--<p><span>入住类型：</span>
		    		<select name="leixing">
		    			<option value="">请选择入住类型</option>
		    		</select>
		    	</p>-->
		    	<div class="kong zt-kong" ></div>
		    	<p style="line-height: 25px;padding: 7.5px 0px;" id="zhuangtai" class="zt-kong"></p>
		    	<div class="kong"></div>
		    	<p><span>真实姓名：</span><input type="text" name="truename" placeholder="请输入真实姓名" id="truename"></p>
		    	<div class="kong"></div>
		    	<p><span>电梯编号：</span><input type="text" name="ecode" placeholder="请输入电梯编号" id="ecode"></p>
		    	<div class="kong"></div>
		    	<p><span>所住楼层：</span><input type="number" name="ceng" placeholder="请输入所住楼层" id="ceng"></p>
		    	<input type="hidden" id="data-id" />
		    	<div class="kong"></div>
		    	<!--<p><span>手机号码：</span><input type="text" name="storephone" placeholder="请输入手机号码"></p>
		    	<p class="yzm"><input type="text" name="yanzhengma" placeholder="输入收到的验证码"><button type="button">获取验证码</button></p>
		        <div class="kong"></div>
		        <p><span>所在地区：</span>
		        	<select name="leixing" style="width: 60%;border: 1px solid #ff7e00!important;">
		    			<option value="">请选择所在地区</option>
		    		</select>
		    		<span style="width: 0.5rem;">区</span>
		        </p>-->
		        <!--<p><span>详细地址：</span><input type="text" name="eara" placeholder="请输入街道门牌号"></p>-->
		        <!--<div class="kong"></div>-->
		        <p class="yyzz"><span>上传房产证</span><input type="file" class="file" id="img"><button type="button">选择文件</button></p>
		        <img src="../images/banner.png" style="display: block;width: 60%;margin:10px auto;" id="yulan"/>
		        <div style="background: #efeff4;padding: 2px 0px;">
		        	 <button class="ch-ph-btn" type="button" style="font-weight: bold;letter-spacing: 2px;">提交申请</button>
		        </div>
		    </form>
		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/session.js"></script>
		<script src="../js/common.js"></script>
		<script type="text/javascript">	
	    var userid=getCookie("userid");
	    if(userid==""||userid==null){
	    	alert(您还没有登录,请先登录)
	    	location.href="../public/login.html"
	    }else{
	    	$.post(net+"/public/index.php?s=api/Predeposit/add_elevator_index/",{"member_id":userid},function(res){
	    		if(res.code=="200"){
	    			if(res.result==null||res.result==""){
	    				$(".zt-kong").hide()
	    			}else{
		    			$("input[name=ecode]").val(res.result.ecode)
		    			$("input[name=truename]").val(res.result.truename)
		    			$("input[name=ceng]").val(res.result.ceng)
		    		    $("#yulan").attr("src",net+res.result.img);
		    		    $("#data-id").val(res.result.id)
		    		    if(res.result.state=="1"){
		    		    	$("#zhuangtai").html("待审核！")
		    		    	$("#zhuangtai").css("color","#007CD9")
		    		    }else if(res.result.state=="2"){
		    		    	$("#zhuangtai").html("审核成功！")
		    		    	$("#zhuangtai").css("color","#007CD9")
		    		    }else if(res.result.state=="-1"){
		    		    	$("#zhuangtai").html("审核审核失败！"+"<br />[失败原因]"+res.result.content)
		    		    	$("#zhuangtai").css("color","#FF0000")
		    		    }
		    		    $(".zt-kong").show()
	    		    }
	    		    
	    		}
	    	})
	    	$("#img").uploadPreview({ Img: "yulan", Width: 120, Height: 120 });
	    	$(".ch-ph-btn").click(function(){
			var $username=/^[\u4e00-\u9fa5]{2,4}$/;
			var $ceng=/^([1-9][0-9]{0,1}|100)$/;
			var truename=$("#truename").val();
			var ecode=$("#ecode").val();
			var ceng=$("#ceng").val();
			var data_id=$("#data-id").val()
			if(truename==null||truename==""){
				alert("请填写真实姓名！")
				return false;
			}else if(!$username.test(truename)){
				alert("真实姓名是2-4位中文");
				return false;
			}else if(ecode==""||ecode==null){
				alert("请填写电梯编号");
				return false;
			}else if(ceng==null||ceng==""){
				alert("请填写楼层");
				return false;
			}else if(!$ceng.test(ceng)){
				alert("楼层数是1-100的整数");
				return false;
			}
		
			var img =document.getElementById("img").files[0]
			var formdate= new FormData();
			formdate.append("member_id",userid)
			formdate.append("truename",truename)
			formdate.append("ecode",ecode)
			formdate.append("ceng",ceng)
			formdate.append("img",img)
			if(data_id!=null&&data_id!=""&&data_id!=undefined){
				formdate.append("id",data_id)
			}
			$.ajax({
				type : "post",
				url : net+"/public/index.php?s=api/Predeposit/add_elevator",
				data : formdate,
				processData:false,
				contentType: false,
				success : function(res) {
					if(res.code=="200"){
						alert(res.message)
//						location.reload();
					}else if(res.code=="10002"){
						alert(res.message)
					}else if(res.code=="10003"){
						alert(res.message)
					}else if(res.code=="10004"){
						alert(res.message)
					}else if(res.code=="10005"){
						alert(res.message)
					}else if(res.code=="10006"){
						alert(res.message)
					}

				}
			});
		});
	    }
		



		</script>
	</body>

</html>